/**
* Copyright @ 2023 iAuto (Shanghai) Co., Ltd.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are NOT permitted except as agreed by
* iAuto (Shanghai) Co., Ltd.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/



import request from '@/utils/request';
import { IAntdTableParams, IPromiseListApi } from '@/types/type';
import { ILogItem, ILogList } from '@/types/log';
import { AntdFormUtils } from 'ahooks/es/useAntdTable/types';
// import { getDateTime } from '@/utils/soa/utils';
import base from "./base";
import moment from "moment";

// 车端系统日志查询
export async function getLogList({ current, pageSize }: IAntdTableParams, formData: AntdFormUtils) {
  const { vin, datetime } = formData;
  const {
    data,
  } = await request.get<IPromiseListApi<ILogList>>(`/${base.API}/ms-soa-operationlog/${base.VERSION}/admin/scenesLog/page`, {
    params: {
      vin,
      createTimeStart: datetime?.[0]?moment(datetime?.[0])?.startOf('day')?.toISOString():undefined,
      createTimeEnd: datetime?.[1]?moment(datetime?.[1])?.endOf('day')?.toISOString():undefined,
      pagesize: pageSize,
      current,
    },
  });
  return {
    list: data?.itemSize
      ? data?.dataList.map((item: ILogItem, index: number) => ({
          ...item,
          index: index + 1 + (current - 1) * pageSize,
        }))
      : [],
    total: data?.pageCount,
  };
}
